package com.hungry.hfw.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import org.springframework.jdbc.core.PreparedStatementCreator;

public class HungryStatementCreator implements PreparedStatementCreator {
	
	private String query;
	private Object[] values;
	private Class<?> className;
	@Override
	public PreparedStatement createPreparedStatement(Connection connection)
			throws SQLException {
		
		PreparedStatement ps = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
		int parameterIndex = 1;
		System.out.println("HungryStatementCreator - query - " + query);
		for (Object param : values) {
			ps.setObject(parameterIndex, param);
			parameterIndex++;
		}
		
		return ps;
	}
	public String getQuery() {
		return query;
	}
	public void setQuery(String query) {
		this.query = query;
	}
	public Object[] getValues() {
		return values;
	}
	public void setValues(Object[] values) {
		this.values = values;
	}
	public void setValues(List<Object> list) {
		if(list!=null) {
			values = new Object[list.size()];
			int counter = 0;
		for(Object o:list) {
			this.values[counter++] = o;
		}
		}
	}
	public void setClassName(Class<?> className) {
		this.className = className;
	}
	public Class<?> getClassName() {
		return className;
	}
	
	
	

}
